package com.etc.mapdemo;

import com.etc.homework.Employee;

import java.util.*;

/**
 * @author: knowno
 * @create: 2024-09-11 10:33
 * @Version 1.0
 **/
public class TestHashMap {
    public static void main(String[] args) {

        Employee employee1 = new Employee("20240001", "张三", "软件开发工程师", 12345);
        Employee employee2 = new Employee("20240002", "留六", "硬件开发工程师", 12345);
        Employee employee3 = new Employee("20240003", "王其", "软件测试工程师", 12345);
        Employee employee4 = new Employee("20240003", "王其", "软件开发工程师", 12345);
        Employee employee5 = new Employee("20240001", "张三", "软件开发工程师", 12345);

        //创建一个HahsMap对象
        HashMap<String, Employee> objectObjectHashMap = new HashMap<>();

        //常见方法 ->key不重复
        objectObjectHashMap.put(employee1.getEmpno(),employee1);
        objectObjectHashMap.put(employee2.getEmpno(),employee2);
        objectObjectHashMap.put(employee3.getEmpno(),employee3);
        objectObjectHashMap.put(employee4.getEmpno(),employee4);
        objectObjectHashMap.put(employee5.getEmpno(),employee5);

        // key-value
        System.out.println(objectObjectHashMap.size());


        //获取key,value,entryset
        System.out.println("*************************************");
        System.out.println(objectObjectHashMap.keySet());
        System.out.println(objectObjectHashMap.values());
        System.out.println(objectObjectHashMap.entrySet());

        System.out.println("*************************************");
        Set<String> keys = objectObjectHashMap.keySet();

        for (String key : keys) {
            //通过key得到value
            System.out.println(objectObjectHashMap.get(key));
        }
        System.out.println("*************************************");
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()){
            System.out.println(objectObjectHashMap.get(iterator.next()));
        }

        System.out.println("*************************************");
        System.out.println(objectObjectHashMap.containsKey("20240003"));

        //创建一个HahsMap对象
        LinkedHashMap<Object, Object> objectObjectLinkedHashMap = new LinkedHashMap<>();

        //创建一个HahsMap对象
        TreeMap<Object, Object> objectObjectTreeMap = new TreeMap<>();

    }
}
